package com.devin.controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("")
public class MyErrorController implements ErrorController {

    @Override
    public String getErrorPath() {
        return "/error";
    }

    @RequestMapping(value = "/error",produces = MediaType.TEXT_HTML_VALUE)
    public String error(HttpServletRequest request){
        int errorCode = (int)request.getAttribute("javax.servlet.error.status_code");
        switch (errorCode){
            case 403:
                return "errorPages/403";
            case 404:
                return "errorPages/404";
            case 500:
                return "errorPages/500";
            case 666:
                return "errorPages/666";
            default:
                return "errorPages/default";
        }
    }
}
